//! Funkcije za pristup vanjskim jedinicama

#ifndef _VJ_SUCELJE_H_
#define _VJ_SUCELJE_H_

/*!
 * Pisanje po 8-bitnom portu
 * \param port Adresa
 * \param data Podatak
 */
static inline void outb (unsigned short int port, unsigned char data)
{
	__asm__ ("outb %b0, %w1" : : "a" (data), "d" (port));
}

/*!
 * Citanje s 8-bitnog porta
 * \param port Adresa
 * \returns Podatak
 */
static inline unsigned char inb (unsigned short int port)
{
	unsigned char r;
	__asm__ __volatile__ ("inb %w1, %b0" : "=a" (r) : "d" (port));
	return r;
}

/*!
 * Pisanje po 16-bitnom portu
 * \param port Adresa
 * \param data Podatak
 */
static inline void outw (unsigned short int port, unsigned short int data)
{
	__asm__ ("outw %w0, %w1" : : "a" (data), "d" (port));
}

/*!
 * Citanje s 16-bitnog porta
 * \param port Adresa
 * \returns Podatak
 */
static inline unsigned short int inw (unsigned short int port)
{
	unsigned short int r;
	__asm__ __volatile__ ("inw %w1, %w0" : "=a" (r) : "d" (port));
	return r;
}

/*!
 * Pisanje stringa po 16-bitnom portu
 */
static inline void outsw (unsigned short int port, const void *data,
	unsigned short int size)
{
	__asm__ __volatile__ (	"cld\n\t"
				"rep outsw\n\t"
				: "+S" (data), "+c" (size) : "d" (port));
}

/*!
 * Citanje stringa s 16-bitnog porta
 */
static inline void insw (unsigned short int port, void *data,
	unsigned short int size)
{
	__asm__ __volatile__ (	"cld\n\t"
				"rep insw\n\t"
				: "+D" (data), "+c" (size) : "d" (port));
}

#endif /* _VJ_SUCELJE_H_ */
